﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DAL;
using Entity;

namespace Project_V1
{
    public partial class FrmSettings : Form
    {
        private SettingsService objSettingsService = new SettingsService();
        private Settings objSettings;//DGV初始加载和选择非当前行触发RowEnter事件,创建objSettings对象,刷新数据显示

        public FrmSettings()
        {
            InitializeComponent();
            this.Load += FrmSettings_Load;
        }

        private void FrmSettings_Load(object sender, EventArgs e)
        {
            this.cbo_Fastener.DropDownStyle = ComboBoxStyle.DropDownList;//下拉列表不可编辑
            this.cbo_Fastener.DataSource = CommonMethods.FastenerList;
            this.cbo_Fastener.DisplayMember = "FastenerName";
            this.cbo_Fastener.ValueMember = "FastenerId";
            this.cbo_LayerStack.DropDownStyle = ComboBoxStyle.DropDownList;//下拉列表不可编辑
            this.cbo_LayerStack.DataSource = CommonMethods.LayerStackList;
            this.cbo_LayerStack.DisplayMember = "LayerStackName";
            this.cbo_LayerStack.ValueMember = "LayerStackId";

            //CommonMethods.SettingsList = objSettingsService.GetAll();//已经在主界面读取过集合
            this.dgv_data.AutoGenerateColumns = false;//只显示自定义的列
            this.dgv_data.DataSource = CommonMethods.SettingsList;

            foreach (Control item in this.MainPanel.Controls)
            {
                if (item is Button)
                {
                    item.Visible = false;
                }
            }
            this.txt_SettingsName.Enabled = false;
            this.txt_SettingsId.Enabled = false;
            this.cbo_Fastener.Enabled = false;
            this.cbo_LayerStack.Enabled = false;
        }

        #region 新增行,需要点击确定\取消
        private void btn_New_Click(object sender, EventArgs e)
        {
            //this.groupBox1.Text = "新增界面";

            this.cbo_Fastener.Enabled = true;
            this.cbo_LayerStack.Enabled = true;
            this.txt_SettingsName.Enabled = true;
            this.txt_SettingsId.Enabled = true;
            this.cbo_Fastener.SelectedIndex = -1;
            this.cbo_LayerStack.SelectedIndex = -1;
            this.txt_SettingsId.Text = "";
            this.txt_SettingsName.Text = "";

            foreach (TabPage page in tabControl1.TabPages)
            {
                foreach (Control item in page.Controls)
                {
                    if (item is TextBox)
                    {
                        item.Enabled = true;
                        item.Text = "";
                    }
                }
            }

            this.dgv_data.Enabled = false;//若点击编辑/新增/删除,DGV不能再选定其他行,不能再次编辑/新增/删除,直到点击确定或取消
            this.btn_Delete.Enabled = false;
            this.btn_New.Enabled = false;
            this.btn_Edit.Enabled = false;

            this.btn_SaveNew.Visible = true;
            this.btn_Cancel.Visible = true;
            this.btn_SaveEdit.Visible = false;
        }
        #endregion

        #region 编辑行,需要点击确定\取消,可继续细化文本改变时才可保存
        private void btn_Edit_Click(object sender, EventArgs e)
        {
            //this.groupBox1.Text = "编辑界面";
            if (this.dgv_data.RowCount == 0)
            {
                MessageBox.Show("没有要编辑的行！", "提示信息");
                return;
            }
            if (this.dgv_data.CurrentRow == null)
            {
                MessageBox.Show("请选中要编辑的行！", "提示信息");
                return;
            }

            foreach (TabPage page in tabControl1.TabPages)
            {
                foreach (Control item in page.Controls)
                {
                    if (item is TextBox)
                    {
                        item.Enabled = true;
                    }
                }
            }
            this.txt_SettingsName.Enabled = true;
            this.txt_SettingsId.Enabled = true;
            this.cbo_Fastener.Enabled = true;
            this.cbo_LayerStack.Enabled = true;

            this.dgv_data.Enabled = false;//若点击编辑/新增/删除,DGV不能再选定其他行,不能再次编辑/新增/删除,直到点击确定或取消
            this.btn_Delete.Enabled = false;
            this.btn_New.Enabled = false;
            this.btn_Edit.Enabled = false;

            this.btn_SaveEdit.Visible = true;
            this.btn_Cancel.Visible = true;
            this.btn_SaveNew.Visible = false;
        }
        #endregion

        #region 删除行,弹出对话框确认是否删除
        private void btn_Delete_Click(object sender, EventArgs e)
        {
            if (this.dgv_data.RowCount == 0)
            {
                MessageBox.Show("没有要删除的行！", "提示信息");
                return;
            }
            if (this.dgv_data.CurrentRow == null)
            {
                MessageBox.Show("请选中要删除的行！", "提示信息");
                return;
            }
            this.dgv_data.Enabled = false;//若点击编辑/新增/删除,DGV不能再选定其他行,不能再次编辑/新增/删除,直到点击确定或取消
            this.btn_Delete.Enabled = false;
            this.btn_New.Enabled = false;
            this.btn_Edit.Enabled = false;

            //弹出对话框,确认是否删除
            string settingsName = this.dgv_data.CurrentRow.Cells["SettingsName"].Value.ToString();
            DialogResult result = MessageBox.Show("确认要删除紧固件  [" + settingsName + "]  吗？", "删除询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (result == DialogResult.Cancel)
            {
                this.dgv_data.Enabled = true;
                this.btn_Delete.Enabled = true;
                this.btn_New.Enabled = true;
                this.btn_Edit.Enabled = true;
                return;
            }

            //获取编号并删除
            string settingsId = this.dgv_data.CurrentRow.Cells["SettingsId"].Value.ToString();
            try
            {
                if (objSettingsService.DeleteSettingsById(settingsId) == 1)
                {
                    //btnQuery_Click(null, null);//同步刷新修改的信息
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示信息");
            }

            UpdateDGV();

            this.dgv_data.Enabled = true;
            this.btn_Delete.Enabled = true;
            this.btn_New.Enabled = true;
            this.btn_Edit.Enabled = true;
        }
        #endregion

        #region 取消按钮
        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            UpdateText();
            this.dgv_data.Enabled = true;//点击取消
            this.btn_Delete.Enabled = true;
            this.btn_New.Enabled = true;
            this.btn_Edit.Enabled = true;

            this.btn_SaveEdit.Visible = false;
            this.btn_SaveNew.Visible = false;
            this.btn_Cancel.Visible = false;
        }
        #endregion

        //弹出MessageBox(更新成功),编辑需封装EditId
        private void btn_SaveEdit_Click(object sender, EventArgs e)
        {
            #region 数据验证,还需要继续添加,comboBox的选择判断

            if (this.cbo_Fastener.SelectedIndex == -1)
            {
                MessageBox.Show("请选择紧固件 ! ", "提示信息");
                this.cbo_Fastener.Focus();
                return;
            }
            if (this.cbo_LayerStack.SelectedIndex == -1)
            {
                MessageBox.Show("请选择板材组合 ! ", "提示信息");
                this.cbo_LayerStack.Focus();
                return;
            }

            if (this.txt_SettingsName.Text.Trim().Length == 0)
            {
                MessageBox.Show("工艺规范名称不能为空 ! ", "提示信息");
                this.txt_SettingsName.Focus();
                return;
            }
            if (this.txt_SettingsId.Text.Trim().Length == 0)
            {
                MessageBox.Show("工艺规范编号不能为空 ! ", "提示信息");
                this.txt_SettingsId.Focus();
                return;
            }
            if (this.txt_TargetVelo1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_TargetVelo1.Focus();
                return;
            }
            if (this.txt_RotationalSpeed1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_RotationalSpeed1.Focus();
                return;
            }
            if (this.txt_TargetPos1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_TargetPos1.Focus();
                return;
            }
            if (this.txt_Bias1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_Bias1.Focus();
                return;
            }
            if (this.txt_TargetDownforce1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_TargetDownforce1.Focus();
                return;
            }
            if (this.txt_TargetTorque1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_TargetTorque1.Focus();
                return;
            }
            if (this.txt_t1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_t1.Focus();
                return;
            }
            if (this.txt_FeedVelo1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_FeedVelo1.Focus();
                return;
            }
            if (this.txt_FeedVelo2.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_FeedVelo2.Focus();
                return;
            }

            //获取选中行的编号
            //this.dgv_data.SelectedRows[0].Cells["SettingsId"].Value
            int a = Convert.ToInt32(this.dgv_data.CurrentRow.Cells["SettingsId"].Value);

            //验证编号是否在数据库内已经存在,并且不等于选中行编号则退出
            if (objSettingsService.IsIdNoExisted(this.txt_SettingsId.Text.Trim()))
            {
                if (a != Convert.ToInt32(this.txt_SettingsId.Text.Trim()))
                {
                    MessageBox.Show("工艺规范编号不能和现有编号重复！", "验证提示");
                    this.txt_SettingsId.Focus();
                    this.txt_SettingsId.SelectAll();
                    return;
                }
            }
            #endregion

            #region 封装工艺规范对象
            Settings objSettings = new Settings()
            {
                MultistageId= Convert.ToInt32(this.txt_MultistageId.Text.Trim()),
                SettingsName = this.txt_SettingsName.Text.Trim(),
                SettingsId = Convert.ToInt32(this.txt_SettingsId.Text.Trim()),
                FastenerId = Convert.ToInt32(this.cbo_Fastener.SelectedValue),
                LayerStackId = Convert.ToInt32(this.cbo_LayerStack.SelectedValue),
                TargetVelo1 = Convert.ToSingle(this.txt_TargetVelo1.Text.Trim()),
                TargetVelo2 = Convert.ToSingle(this.txt_TargetVelo2.Text.Trim()),
                TargetVelo3 = Convert.ToSingle(this.txt_TargetVelo3.Text.Trim()),
                TargetVelo4 = Convert.ToSingle(this.txt_TargetVelo4.Text.Trim()),
                TargetVelo5 = Convert.ToSingle(this.txt_TargetVelo5.Text.Trim()),
                RotationalSpeed1 = Convert.ToSingle(this.txt_RotationalSpeed1.Text.Trim()),
                RotationalSpeed2 = Convert.ToSingle(this.txt_RotationalSpeed2.Text.Trim()),
                RotationalSpeed3 = Convert.ToSingle(this.txt_RotationalSpeed3.Text.Trim()),
                RotationalSpeed4 = Convert.ToSingle(this.txt_RotationalSpeed4.Text.Trim()),
                RotationalSpeed5 = Convert.ToSingle(this.txt_RotationalSpeed5.Text.Trim()),
                TargetPos1 = Convert.ToSingle(this.txt_TargetPos1.Text.Trim()),
                TargetPos2 = Convert.ToSingle(this.txt_TargetPos2.Text.Trim()),
                TargetPos3 = Convert.ToSingle(this.txt_TargetPos3.Text.Trim()),
                TargetPos4 = Convert.ToSingle(this.txt_TargetPos4.Text.Trim()),
                TargetPos5 = Convert.ToSingle(this.txt_TargetPos5.Text.Trim()),
                Bias1 = Convert.ToSingle(this.txt_Bias1.Text.Trim()),
                TargetDownforce1 = Convert.ToSingle(this.txt_TargetDownforce1.Text.Trim()),
                TargetTorque1 = Convert.ToSingle(this.txt_TargetTorque1.Text.Trim()),
                T1 = Convert.ToSingle(this.txt_t1.Text.Trim()),
                FeedVelo1 = Convert.ToSingle(this.txt_FeedVelo1.Text.Trim()),
                FeedVelo2 = Convert.ToSingle(this.txt_FeedVelo2.Text.Trim()),
                EidtId = a
            };

            #endregion

            #region 调用后台数据访问方法,将对象信息存入数据库
            try
            {
                if (objSettingsService.ModifySettings(objSettings) == 1)
                {
                    MessageBox.Show("工艺规范参数更新成功", "提示信息");
                }
                else
                {
                    MessageBox.Show("更新失败", "提示信息");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion

            UpdateDGV();

            this.dgv_data.Enabled = true;//点击确定,编辑完成
            this.btn_Delete.Enabled = true;
            this.btn_New.Enabled = true;
            this.btn_Edit.Enabled = true;

            this.btn_SaveEdit.Visible = false;
            this.btn_SaveNew.Visible = false;
            this.btn_Cancel.Visible = false;
        }

        private void btn_SaveNew_Click(object sender, EventArgs e)
        {
            #region 数据验证,还需要继续添加,comboBox的选择判断

            if (this.cbo_Fastener.SelectedIndex == -1)
            {
                MessageBox.Show("请选择紧固件 ! ", "提示信息");
                this.cbo_Fastener.Focus();
                return;
            }
            if (this.cbo_LayerStack.SelectedIndex == -1)
            {
                MessageBox.Show("请选择板材组合 ! ", "提示信息");
                this.cbo_LayerStack.Focus();
                return;
            }

            if (this.txt_SettingsName.Text.Trim().Length == 0)
            {
                MessageBox.Show("工艺规范名称不能为空 ! ", "提示信息");
                this.txt_SettingsName.Focus();
                return;
            }
            if (this.txt_SettingsId.Text.Trim().Length == 0)
            {
                MessageBox.Show("工艺规范编号不能为空 ! ", "提示信息");
                this.txt_SettingsId.Focus();
                return;
            }
            if (this.txt_TargetVelo1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_TargetVelo1.Focus();
                return;
            }
            if (this.txt_RotationalSpeed1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_RotationalSpeed1.Focus();
                return;
            }
            if (this.txt_TargetPos1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_TargetPos1.Focus();
                return;
            }
            if (this.txt_Bias1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_Bias1.Focus();
                return;
            }
            if (this.txt_TargetDownforce1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_TargetDownforce1.Focus();
                return;
            }
            if (this.txt_TargetTorque1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_TargetTorque1.Focus();
                return;
            }
            if (this.txt_t1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_t1.Focus();
                return;
            }
            if (this.txt_FeedVelo1.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_FeedVelo1.Focus();
                return;
            }
            if (this.txt_FeedVelo2.Text.Trim().Length == 0)
            {
                MessageBox.Show("设备控制参数不能为空 ! ", "提示信息");
                this.txt_FeedVelo2.Focus();
                return;
            }

            //验证编号是否在数据库内已经存在
            if (objSettingsService.IsIdNoExisted(this.txt_SettingsId.Text.Trim()))
            {
                MessageBox.Show("工艺规范编号不能和现有编号重复！", "验证提示");
                this.txt_SettingsId.Focus();
                this.txt_SettingsId.SelectAll();
                return;
            }
            #endregion

            #region 封装工艺规范对象
            Settings objSettings = new Settings()
            {
                MultistageId = Convert.ToInt32(this.txt_MultistageId.Text.Trim()),
                SettingsName = this.txt_SettingsName.Text.Trim(),
                SettingsId = Convert.ToInt32(this.txt_SettingsId.Text.Trim()),
                FastenerId = Convert.ToInt32(this.cbo_Fastener.SelectedValue),
                LayerStackId = Convert.ToInt32(this.cbo_LayerStack.SelectedValue),
                TargetVelo1 = Convert.ToSingle(this.txt_TargetVelo1.Text.Trim()),
                TargetVelo2 = Convert.ToSingle(this.txt_TargetVelo2.Text.Trim()),
                TargetVelo3 = Convert.ToSingle(this.txt_TargetVelo3.Text.Trim()),
                TargetVelo4 = Convert.ToSingle(this.txt_TargetVelo4.Text.Trim()),
                TargetVelo5 = Convert.ToSingle(this.txt_TargetVelo5.Text.Trim()),
                RotationalSpeed1 = Convert.ToSingle(this.txt_RotationalSpeed1.Text.Trim()),
                RotationalSpeed2 = Convert.ToSingle(this.txt_RotationalSpeed2.Text.Trim()),
                RotationalSpeed3 = Convert.ToSingle(this.txt_RotationalSpeed3.Text.Trim()),
                RotationalSpeed4 = Convert.ToSingle(this.txt_RotationalSpeed4.Text.Trim()),
                RotationalSpeed5 = Convert.ToSingle(this.txt_RotationalSpeed5.Text.Trim()),
                TargetPos1 = Convert.ToSingle(this.txt_TargetPos1.Text.Trim()),
                TargetPos2 = Convert.ToSingle(this.txt_TargetPos2.Text.Trim()),
                TargetPos3 = Convert.ToSingle(this.txt_TargetPos3.Text.Trim()),
                TargetPos4 = Convert.ToSingle(this.txt_TargetPos4.Text.Trim()),
                TargetPos5 = Convert.ToSingle(this.txt_TargetPos5.Text.Trim()),
                Bias1 = Convert.ToSingle(this.txt_Bias1.Text.Trim()),
                TargetDownforce1 = Convert.ToSingle(this.txt_TargetDownforce1.Text.Trim()),
                TargetTorque1 = Convert.ToSingle(this.txt_TargetTorque1.Text.Trim()),
                T1 = Convert.ToSingle(this.txt_t1.Text.Trim()),
                FeedVelo1 = Convert.ToSingle(this.txt_FeedVelo1.Text.Trim()),
                FeedVelo2 = Convert.ToSingle(this.txt_FeedVelo2.Text.Trim())                
            };

            #endregion

            #region 调用后台数据访问方法,将对象信息存入数据库
            try
            {
                if (objSettingsService.AddSettings(objSettings) == 1)
                {
                    MessageBox.Show("新工艺规范添加成功", "提示信息");
                }
                else
                {
                    MessageBox.Show("添加失败", "提示信息");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion

            UpdateDGV();

            this.dgv_data.Enabled = true;//点击确定,编辑完成
            this.btn_Delete.Enabled = true;
            this.btn_New.Enabled = true;
            this.btn_Edit.Enabled = true;

            this.btn_SaveEdit.Visible = false;
            this.btn_SaveNew.Visible = false;
            this.btn_Cancel.Visible = false;
        }

        #region 被选中行RowEnter事件,得到被选中行的索引值,和SettingsList集合的索引一一对应
        private void dgv_data_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            //DGV初始加载和选择非当前行触发RowEnter事件,该事件结束后CurrentRow属性才会被更新
            objSettings = new Settings();
            int i = e.RowIndex;//索引值按照由小到大,集合由数据库默认按照主键增序存入,索引一一对应
            objSettings = CommonMethods.SettingsList[i];
            //objSettings.EidtId = Convert.ToInt32(this.dgv_data.Rows[i].Cells["SettingsId"].Value);
            UpdateText();
        }
        #endregion

        #region UpdateDGV()从数据库读取信息存入集合,重新绑定刷新DataGridView
        private void UpdateDGV()//从数据库读取集合信息
        {
            CommonMethods.SettingsList = objSettingsService.GetAll();
            this.dgv_data.DataSource = null;
            this.dgv_data.DataSource = CommonMethods.SettingsList;
        }
        #endregion

        #region UpdateText()更新文本等显示
        /// <summary>
        /// 更新TextBox等显示
        /// </summary>
        private void UpdateText()//TextBox赋值并置为不可编辑
        {
            this.txt_MultistageId.Text = objSettings.MultistageId.ToString();
            this.txt_SettingsName.Text = objSettings.SettingsName;
            this.txt_SettingsId.Text = objSettings.SettingsId.ToString();
            this.txt_TargetVelo1.Text = objSettings.TargetVelo1.ToString();
            this.txt_TargetVelo2.Text = objSettings.TargetVelo2.ToString();
            this.txt_TargetVelo3.Text = objSettings.TargetVelo3.ToString();
            this.txt_TargetVelo4.Text = objSettings.TargetVelo4.ToString();
            this.txt_TargetVelo5.Text = objSettings.TargetVelo5.ToString();
            this.txt_RotationalSpeed1.Text = objSettings.RotationalSpeed1.ToString();
            this.txt_RotationalSpeed2.Text = objSettings.RotationalSpeed2.ToString();
            this.txt_RotationalSpeed3.Text = objSettings.RotationalSpeed3.ToString();
            this.txt_RotationalSpeed4.Text = objSettings.RotationalSpeed4.ToString();
            this.txt_RotationalSpeed5.Text = objSettings.RotationalSpeed5.ToString();
            this.txt_TargetPos1.Text = objSettings.TargetPos1.ToString();
            this.txt_TargetPos2.Text = objSettings.TargetPos2.ToString();
            this.txt_TargetPos3.Text = objSettings.TargetPos3.ToString();
            this.txt_TargetPos4.Text = objSettings.TargetPos4.ToString();
            this.txt_TargetPos5.Text = objSettings.TargetPos5.ToString();
            this.txt_Bias1.Text = objSettings.Bias1.ToString();
            this.txt_TargetDownforce1.Text = objSettings.TargetDownforce1.ToString();
            this.txt_TargetTorque1.Text = objSettings.TargetTorque1.ToString();
            this.txt_t1.Text = objSettings.T1.ToString();
            this.txt_FeedVelo1.Text = objSettings.FeedVelo1.ToString();
            this.txt_FeedVelo2.Text = objSettings.FeedVelo2.ToString();

            this.cbo_Fastener.DataSource = null;
            this.cbo_Fastener.DisplayMember = "FastenerName";
            this.cbo_Fastener.ValueMember = "FastenerId";
            this.cbo_Fastener.DataSource = CommonMethods.FastenerList;

            this.cbo_LayerStack.DataSource = null;
            this.cbo_LayerStack.DisplayMember = "LayerStackName";
            this.cbo_LayerStack.ValueMember = "LayerStackId";
            this.cbo_LayerStack.DataSource = CommonMethods.LayerStackList;

            this.cbo_Fastener.SelectedValue = objSettings.FastenerId;
            this.cbo_LayerStack.SelectedValue = objSettings.LayerStackId;
            this.cbo_Fastener.Enabled = false;
            this.cbo_LayerStack.Enabled = false;
            this.txt_SettingsName.Enabled = false;
            this.txt_SettingsId.Enabled = false;

            foreach (TabPage page in tabControl1.TabPages)
            {
                foreach (Control item in page.Controls)
                {
                    if (item is TextBox)
                    {
                        item.Enabled = false;
                    }
                }
            }
        }

        #endregion

        private void dgv_data_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            this.btn_Edit_Click(null, null);
        }

    }
}
